package com.cnhis.drgs.vo;



import com.cnhis.drgs.enums.OrderByEnum;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页对象
 */
public class Page extends Condition {

    private int pageNum = 1;// 总页数
    private int pageNo = 1;// 当前页
    private int pageSize = 10;// 一页放的数据条数
    private int rowCount = 0;// 总记录数
    private int offset;//从多少条位置开始读取，用作分页 limit offset,pageSize

    private String sort;// 排序字段
    private String order;// 排序类型

    // 本页数据
    private List list = new ArrayList<>();

    public Page() {

    }

    public Page(int pageSize) {
        this.pageSize = pageSize;
    }

    public Page(int pageSize, int pageNo) {
        this.pageSize = pageSize;
        this.pageNo = pageNo;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
        pageNum = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1;
    }

    public int getOffset() {
        return offset = (pageNo - 1) * pageSize;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public String getSort() {
        return sort;
    }

    // 根据什么字段排序
    public void setSort(String sort) {
        if (StringUtils.isNotBlank(sort)) {
            sort = sort.replace("'", "");
        }
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(OrderByEnum orderBy) {
        if (orderBy != null) {
            this.order = orderBy.name();
        } else {
            this.order = null;
        }
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

}
